package com.bobo.myapplication.utils;

import android.util.Log;
import android.view.View;

import com.bobo.myapplication.R;

/**
 * Created by ZJB on 2018/1/2.
 *
 * @ copyright: iwhere chengdu technology
 */

public class StringUtil {

    private static final String TAG = StringUtil.class.getSimpleName();

    public static boolean isFastClick(View clickView, long ms) {
        Object tag = clickView.getTag(R.id.fastClick_view_tag);
        Log.e(TAG, "isFastClick: tag"+tag );
        if (tag instanceof Long) {
            long lastTime = (long) tag;
            long nowTime = System.currentTimeMillis();
            clickView.setTag(R.id.fastClick_view_tag, nowTime);
            Log.e(TAG, "isFastClick1:lastTime-> "+lastTime+" nowTime->"+nowTime);
            return nowTime - lastTime < ms;
        } else if (tag == null) {
            clickView.setTag(R.id.fastClick_view_tag,System.currentTimeMillis());
            Log.e(TAG, "isFastClick2:tag->null");
            return false;
        } else {
            throw new IllegalStateException("clickView can not setTag by key:fastClick_view_tag");
        }
    }

    public static boolean isFastClick(View clickView) {
        return isFastClick(clickView, 1000);
    }
}
